<?php
defined('_JEXEC') or die('Restricted access');

$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$input = $app->input;
$itemid = $input->get('Itemid');
$scale = $input->get('scale','day');
$item  = $input->getArray();
$activeUsers = json_decode($item['jsonData'],true);
$series = $activeUsers['series'];
if($series){
	$maxValue = 4;
    foreach ($series['data']  as $v) {
        $times[] = $v['time'];
        $values[] = $v['value'];
        if ($v['value'] > $maxValue)
        	$maxValue = $v['value'];
    }
    
    if ($maxValue % 4 != 0)
    	$maxValue += (4 - $maxValue % 4);
    
    $interval = $maxValue / 4;
}

$vName = $input->get('view');
?>
<div class="res-title-rg">
	<span class="fl pos-icon text-c"><i class="acquisition"></i></span>
	<div class="title-info">
		<h2 class="fontsize20">New Users</h2>
		<p><a href="#">Home</a>&nbsp;/&nbsp;<a href="#">Acquisition</a>&nbsp;/&nbsp;New Users</p>
	</div>
</div>
<div class="ws-content pdall15">
<div class="camtab">
	<nav>
		<ul class="pagination navmg fr" id="u385_input">
			<li><a href="/index.php?option=com_console&view=<?php echo $vName; ?>&task=NewUsers&Itemid=<?php echo $itemid ?>&scale=hourly" <?php if($scale=='hourly'): ?>class="selected"<?php endif;?>>Hourly</a></li>
			<li><a href="/index.php?option=com_console&view=<?php echo $vName; ?>&task=NewUsers&Itemid=<?php echo $itemid ?>&scale=day" <?php if($scale=='day'): ?>class="selected"<?php endif;?>>Day</a></li>
			<li><a href="/index.php?option=com_console&view=<?php echo $vName; ?>&task=NewUsers&Itemid=<?php echo $itemid ?>&scale=week" <?php if($scale=='week'): ?>class="selected"<?php endif;?>>Week</a></li>
			<li><a href="/index.php?option=com_console&view=<?php echo $vName; ?>&task=NewUsers&Itemid=<?php echo $itemid ?>&scale=month" <?php if($scale=='month'): ?>class="selected"<?php endif;?>>Month</a></li>
		</ul>
	</nav>
	<div class="clear"></div>
</div>
<?php if ($series['data']): ?>
    <div id="main" style="height:520px;"></div>
</div>
<script type="text/javascript">
	createLineChart({
		divId: 'main',
		title: '<?php echo $series['name']?>',
		isHourView:
	<?php if ($scale == 'hourly'):?>
		true
	<?php else:?>
		false
	<?php endif?>,
		xitems: <?php echo json_encode($times)?>,
		yitems: <?php echo json_encode($values)?>,
		xTitle: 'Time',
		yTitle: 'New Users'		
	});
    
</script>
<?php else: ?>
 	<p class="ws-tips">No report data found.</p>
<?php endif; ?>
